package com.sc.nft.controller;

import cn.hutool.core.util.StrUtil;
import com.sc.nft.annotation.WithoutSign;
import com.sc.nft.controller.request.OneClickImportRequest;
import com.sc.nft.entity.dto.ConsignmentRecordDTO;
import com.sc.nft.entity.dto.DingLianTransactionRecordDTO;
import com.sc.nft.entity.vo.ConsignmentRecordVO;
import com.sc.nft.entity.vo.DingLianDealPracticalVO;
import com.sc.nft.entity.vo.DingLianTransactionRecordVO;
import com.sc.nft.entity.vo.LargeDiskAccessVO;
import com.sc.nft.service.*;
import com.sc.nft.sup.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import springfox.documentation.annotations.ApiIgnore;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

@Slf4j
@RequiredArgsConstructor
@RestController
@RequestMapping("/chainPegging")
@Api(tags = "盯链")
@ApiIgnore
public class ChainPeggingController {

    private final SecondOrderService secondOrderService;
    private final UserCollectionService userCollectionService;
    private final DigitalCollectionService digitalCollectionService;
    private final TradingPoolOrderService tradingPoolOrderService;
    private final ChainPeggingService chainPeggingService;


    @ApiOperation(value = "交易实盘", notes = "交易实盘", httpMethod = "POST", produces = MediaType.APPLICATION_JSON_VALUE)
    @GetMapping(value = "/dealPractical", produces = MediaType.APPLICATION_JSON_VALUE)
    @WithoutSign
    public Result<List<DingLianDealPracticalVO>> dealPractical() {
        List<DingLianDealPracticalVO> dealPracticalVOList = new ArrayList<>();
        //region 生态藏品二级订单和交易池订单
        List<DingLianDealPracticalVO> dealPracticalInConsensusList = secondOrderService.dealPracticalInConsensus();
        List<DingLianDealPracticalVO> dealTradingPracticalInConsensusList = tradingPoolOrderService.dealTradingPracticalInConsensus();
        //endregion
        //region 非生态藏品二级订单和交易池订单
        List<DingLianDealPracticalVO> dealPracticalNotInConsensusList = secondOrderService.dealPracticalNotInConsensus();
        List<DingLianDealPracticalVO> dealTradingPracticalNotInConsensusList = tradingPoolOrderService.dealTradingPracticalNotInConsensus();
        //endregion
        dealPracticalVOList.addAll(chainPeggingService.dealPractical(dealPracticalInConsensusList, dealTradingPracticalInConsensusList));
        dealPracticalVOList.addAll(chainPeggingService.dealPractical(dealPracticalNotInConsensusList, dealTradingPracticalNotInConsensusList));
        return Result.success(dealPracticalVOList);
    }

    @ApiOperation(value = "交易记录", notes = "交易记录", httpMethod = "POST", produces = MediaType.APPLICATION_JSON_VALUE)
    @GetMapping(value = "/transactionRecord", produces = MediaType.APPLICATION_JSON_VALUE)
    @WithoutSign
    public Result<List<DingLianTransactionRecordVO>> transactionRecord(DingLianTransactionRecordDTO dto) {
        return Result.success(secondOrderService.transactionRecord(dto));
    }


    @ApiOperation(value = "寄售记录", notes = "寄售记录", httpMethod = "POST", produces = MediaType.APPLICATION_JSON_VALUE)
    @GetMapping(value = "/consignmentRecord", produces = MediaType.APPLICATION_JSON_VALUE)
    @WithoutSign
    public Result<List<ConsignmentRecordVO>> consignmentRecord(ConsignmentRecordDTO dto) {
        return Result.success(secondOrderService.consignmentRecord(dto));
    }

    @ApiOperation(value = "大盘接入", notes = "大盘接入", httpMethod = "GET", produces = MediaType.APPLICATION_JSON_VALUE)
    @GetMapping(value = "/largeDiskAccess", produces = MediaType.APPLICATION_JSON_VALUE)
    @WithoutSign
    public Result<List<LargeDiskAccessVO>> largeDiskAccess() {
        return Result.success(digitalCollectionService.largeDiskAccess());
    }

    @ApiOperation(value = "一键导入", notes = "一键导入", httpMethod = "GET", produces = MediaType.APPLICATION_JSON_VALUE)
    @GetMapping(value = "/oneClickImport", produces = MediaType.APPLICATION_JSON_VALUE)
    @WithoutSign
    public HashMap oneClickImport(OneClickImportRequest request) {
        HashMap<String, Object> result = new HashMap<>();
        if (StrUtil.isBlank(request.getUserMobile()) && StrUtil.isBlank(request.getUserAddress())) {
            result.put("err", Boolean.TRUE);
            result.put("msg", "请输入手机号或者地址");
            return result;
        }
        return userCollectionService.oneClickImport(request.getUserMobile(), request.getUserAddress(), request.getPage());
    }
}
